import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from "@angular/common/http";

import { Observable } from "rxjs";

@Injectable({
    providedIn: 'root'
})
export class DepartmentManageService {

    private baseUrl: string = "/api/dept"
    
    constructor(
        private http : HttpClient
    ) { }

    apiList(data) : Observable<any>{
        let _dataJson = {
            params : data
        }
        return this.http.get(this.baseUrl, _dataJson).pipe()
    }
    apiEdit(data) : Observable<any>{
        let _dataJson = {
            ...data
        }
        return this.http.put(this.baseUrl, _dataJson).pipe();
    }
    apiAdd(data) : Observable<any>{
        let _dataJson = {
            ...data,
            enabled : data.enabled,
            pid : !data.pid ? 0 : data.pid
        }

        return this.http.post(this.baseUrl, _dataJson).pipe();
    }
    apiDelete( data ) : Observable<any>{
        let _dataJson = {
            headers : new HttpHeaders({
                'Content-Type': 'application/json',
            }),
            body : data
        }
        return this.http.delete(this.baseUrl, _dataJson).pipe();
    }
}
